package DBSystem.analyze;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;

import java_cup.runtime.Symbol;


public class ParserTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		//SQLexer lexer = new SQLexer(new StringReader("SELECT * FROM testtabelle;"));
		//SQLexer lexer = new SQLexer(new StringReader("CREATE TABLE testtabelle (INT attr1, CHAR attr2);"));
		//SQLexer lexer = new SQLexer(new StringReader("DROP TABLE testtabelle;"));
		SQLexer lexer = new SQLexer(new StringReader("INSERT INTO testtabelle (attr1, attr2) VALUES (45,  p);"));
		
		Parser parser = new Parser(lexer);
		Object result = parser.parse();
		if (result instanceof Select) {
			Select select = (Select)result;
			System.out.println("Select statement parsed:");
			System.out.println("   selectAll: "+select.selectAll);
			System.out.println("   tablename: "+select.tablename);
		}
		
		if (result instanceof Create) {
			Create create = (Create)result;
			System.out.println("Create statement parsed:");
			System.out.println("   tablename: "+create.tablename);
			System.out.println("   attributes:");
			for (CreateAttribute ca: create.attributes) {
				System.out.println("      type: "+ca.datatype+" name:"+ca.name);
			}
		}
		
		if (result instanceof Drop) {
			Drop drop = (Drop)result;
			System.out.println("Drop statement parsed:");
			System.out.println("   tablename: "+drop.tablename);
		}
		
		if (result instanceof Insert) {
			Insert insert = (Insert)result;
			System.out.println("Insert statement parsed:");
			System.out.println("   tablename: "+insert.tablename);
			for (String attr: insert.attributes) {
				System.out.println("      attribute: "+attr);
			}
			for (String value: insert.values) {
				System.out.println("      value: "+value);
			}
		}
	}

}
